package com.sun.handler;

import java.util.Hashtable;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.Bean.ConfigFileBean;
import com.sun.Bean.ServerDataMeta;
import com.sun.Data.Interface.IServerDataHandler;
import com.sun.DataHandler.Impl.ConfigFIleHandler;
import com.sun.common.CommonMetaData;

public class RequestConfigHandler extends IoHandlerAdapter  {

	static final Logger logger = LoggerFactory.getLogger(RequestConfigHandler.class);
	
	String spliterString=";";
	
	final String keySplit="=";
	
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		
		Hashtable<String, String> paramMap = new Hashtable<String, String>();
		
		String msg = (String)message;
		
		String[] msgArray=msg.split(spliterString);
		
		for(String str:msgArray){
			
			String[] pp=str.split(keySplit);
			
			paramMap.put(pp[0],pp[1]);
			
		}
		
		paramMap.get(CommonMetaData.PROJECT_ID);
		
		ServerDataMeta metaData = new ServerDataMeta(paramMap);
		
		IServerDataHandler handler = new ConfigFIleHandler();

		Hashtable<String, Hashtable<String, ConfigFileBean>> resultString = handler.handle(metaData);
		
		session.write(resultString);
		
		//paramMap
		
		//logger.info("Message:"+(String)message);
		
	}
	
}
